<template>
  <view @touchmove.stop.prevent>
    <view
      class="es-bottom-popup"
      :class="{ 'es-popup--show': show, 'es-popup--radius': radius }"
      :style="{
        backgroundColor: backgroundColor,
        height: height ? height + 'rpx' : 'auto',
        zIndex: zIndex,
        transform: `translate3d(0, ${show ? translateY : '100%'}, 0)`,
      }"
    >
      <slot></slot>
    </view>
    <view
      class="es-popup__mask"
      :class="[show ? 'es-mask--show' : '']"
      :style="{ zIndex: maskZIndex }"
      v-if="mask"
      @tap="handleClose"
    ></view>
  </view>
</template>

<script lang="ts" setup>
withDefaults(
  defineProps<{
    mask?: boolean
    show?: boolean
    backgroundColor?: string
    height?: number
    radius?: boolean
    zIndex?: string | number
    maskZIndex?: string | number
    translateY?: string
  }>(),
  {
    mask: true,
    show: false,
    backgroundColor: '#fff',
    height: 0,
    radius: true,
    zIndex: 997,
    maskZIndex: 996,
    translateY: '0',
  },
)
const state = reactive({})
function handleClose() {}
</script>

<style lang="scss" scoped>
.es-bottom-popup {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  min-height: 20rpx;
  opacity: 0;
  transition: all 0.3s ease-in-out;
  transform: translate3d(0, 100%, 0);
  transform-origin: center;
}

.es-popup--radius {
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  border-top-left-radius: 24rpx;
  border-top-right-radius: 24rpx;
}

.es-popup--show {
  opacity: 1;
}

.es-popup__mask {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  visibility: hidden;
  background-color: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: all 0.3s ease-in-out;
}

.es-mask--show {
  visibility: visible;
  opacity: 1;
}
</style>
